package com.liu.springmvc.servlet;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.http.HttpServlet;

/**
 * @author LIU
 * @version 1.0
 * @date 2024/1/26 11:15
 * @description TODO
 * 框架基础servlet
 *   负责初始化spring容器
 */
public abstract class FrameworkServlet extends HttpServlet {

    private ClassPathXmlApplicationContext applicationContext;


    @Override
    public void init(){
        System.out.println("servlet.init 初始化了");

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:springmvc.xml");
//        context.refresh();
        this.applicationContext = context;

        // 子类实现初始化springMVC九大组件
        onRefresh(context);
    }


    public final ApplicationContext getWebApplicationContext() {
        return this.applicationContext;
    }


    protected abstract void onRefresh(ApplicationContext context);
}
